<template>
    <div class="swiper">
        <el-carousel :interval="swiperTime" :direction="swiperImgType" arrow="always" height="677px" :type="swiperType">
            <el-carousel-item v-for="item in imgItem" :key="item.id">
                <img :src="item.swiperAddress" class="img-swiper">
            </el-carousel-item>
        </el-carousel>
    </div>
</template>

<script>

    import swiperApi from '@/api/swiperApi'

    export default {
        name: "CmsSwiper",
        data(){
            return{
                imgItem:[],
                swiperTime:4000,
                swiperImgType:'horizontal',
                swiperType:''
            }
        },
        created:async function () {
            let res = await swiperApi.swiperDetail();
            if(res.code == '200'){
                this.imgItem = res.data
            }

            //查询key,轮播图类型
            let res2 = await swiperApi.getByKey("swiperType")
            if (res2.code == '200'){
                if (res2.data.paramValue == '1'){
                    this.swiperType = 'card'
                }
            }

            //查询key，轮播图切换时间
            let res3 = await swiperApi.getByKey("swiperTime")
            if (res3.code == '200'){
                this.swiperTime = parseInt(res3.data.paramValue);
            }

            //查询key，轮播图风格
            let res4 = await swiperApi.getByKey("swiperImgType")
            if (res4.code == '200'){
                if (res4.data.paramValue == '1'){
                    this.swiperImgType = 'horizontal'
                }
                if (res4.data.paramValue == '2'){
                    this.swiperImgType = 'vertical'
                }
            }

        }
    }
</script>

<style scoped>
    .el-carousel__item h3 {
        color: #475669;
        font-size: 18px;
        opacity: 0.75;
        line-height: 300px;
        margin: 0;
    }

    .el-carousel__item:nth-child(2n) {
        background-color: #99a9bf;
    }

    .el-carousel__item:nth-child(2n+1) {
        background-color: #d3dce6;
    }
    .img-swiper{
        width: 100%;
        height: 100%;
    }

</style>